/*
 * @Date: 2023-10-18 14:56:15
 * @LastEditTime: 2024-01-22 13:46:13
 */
import utils from 'service/utils';
import Loading from 'service/Loading.vue';
import { Swiper, SwiperSlide} from 'vue-awesome-swiper'
var wait = 60; //验证码倒计时
const baseCompent = {
    created() {},
    components: {
        Loading,
        Swiper,
        SwiperSlide,
    },
    computed: {
        
    },
    data() {
        let that = this;
        return {
            swiperOption: {
                //direction: 'vertical',
                //effect: 'fade',
                //loop:true,
                fadeEffect: {
                    crossFade: true
                },
                resistanceRatio: 0,
                initialSlide: 0,
                touchMoveStopPropagation: false,
                speed: 500,
            }
        };
    },
    mounted() {
        
        
    },
    methods: {
        topFunction() {
            document.body.scrollTop = 0;
            document.documentElement.scrollTop = 0;
          },
          openOffAccount(obj, elem) {
            $(obj).siblings().removeClass("active");
            $(obj).addClass("active");
            if (elem == "") {
              $(".officialAccount").hide();
              $(".officialAccount").removeClass("active");
              $("#myModal #myModalLabel").text("资料获取");
            } else {
              $("#" + elem)
                .siblings(".officialAccount")
                .hide();
              $("#" + elem)
                .siblings(".officialAccount")
                .removeClass("active");
              if ($("#" + elem).hasClass("active")) {
                $("#" + elem).hide();
                $("#" + elem).removeClass("active");
              } else {
                $("#" + elem).show();
                $("#" + elem).addClass("active");
              }
            }
          },
      
          closeOffComAccount(elem) {
            $("#contInfoSider .leftBoxLine").removeClass("active");
            $(".officialAccount").removeClass("active");
            $("#" + elem).hide();
          },
      
          lxSubmit() {
            if ($("#verifyCode").val() == "") {
              alert("验证码不得为空!");
              return false;
            }
            if ($("#name").val() == "") {
              alert("姓名不得为空!");
              return false;
            }
            if ($("#company").val() == "") {
              alert("公司不得为空!");
              return false;
            }
            if ($("#city").val() == "") {
              alert("城市不得为空!");
              return false;
            }
            if ($("#phone").val() == "") {
              alert("电话不得为空!");
              return false;
            }
            if ($("#email").val() == "") {
              alert("Email不得为空!");
              return false;
            }
            if (!isPhone($("#phone").val())) {
              alert("电话格式不合法!");
              return false;
            }
            if (!isEmail($("#email").val())) {
              alert("邮箱格式不合法!");
              return false;
            }
            $.ajax({
              url: "addMessage.do",
              type: "post",
              data: {
                name: $("#name").val(),
                company: $("#company").val(),
                city: $("#city").val(),
                phone: $("#phone").val(),
                email: $("#email").val(),
                message: $("#message").val(),
                verifyCode: $("#verifyCode").val(),
              },
              dataType: "json",
              success: function (data) {
                if (data.success) {
                  alert("提交成功!");
                  $("#myModal").modal("hide");
                } else {
                  alert(data.message);
                }
              },
            });
          },
      
          isPhone(str) {
            var re = /0?(13|14|15|18|17)[0-9]{9}/;
            var re1 = /[0-9-()（）]{7,18}/;
            str += "";
            return re.test(str) || re1.test(str);
          },
      
          isEmail(str) {
            var re = /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/;
            str += "";
            return re.test(str);
          },
      
          sendCode() {
            if ($("#phone").val() == "") {
              alert("电话不得为空!");
              return false;
            }
            $.ajax({
              url: "sendCode.do",
              type: "post",
              data: {
                phone: $("#phone").val(),
              },
              dataType: "json",
              success: function (data) {
                if (data.success) {
                  alert(data.message);
                  time(this);
                } else {
                  alert(data.message);
                }
              },
            });
          },
          time(obj) {
            if (wait == 0) {
              $("#getCode").removeAttr("disabled");
              $("#getCode").html("发送验证码");
              wait = 60;
            } else {
              $("#getCode").attr("disabled", "true");
              $("#getCode").html(wait + "秒后重试");
              wait--;
              setTimeout(function () {
                //倒计时方法
                time(obj);
              }, 1000); //间隔为1s
            }
          },
    }
};
export default baseCompent;
